﻿using BootstrapBlazor.Components;
using Microsoft.AspNetCore.Components;

namespace OnWork.DataCenter.Shared.Pages.DataStandard.Designer
{
    /// <summary>
    /// 弹出对话框
    /// </summary>
    public partial class StandardDesignerDialog : ComponentBase, IResultDialog
    {
        private StandardDesigner designer;

        /// <summary>
        /// 当初始化执行完之后
        /// </summary>
        [Parameter]
        public Action<StandardDesigner> OnLoadedAction { get; set; }

        protected override void OnAfterRender(bool firstRender)
        {
            base.OnAfterRender(firstRender);
            if (firstRender) {
                if (OnLoadedAction != null)
                {
                    OnLoadedAction(designer);
                }
            }
        }

        protected override void OnInitialized()
        {
            base.OnInitialized();
        }

        /// <summary>
        ///
        /// </summary>
        [Parameter]
        public EventCallback<(string,string)> ValueChanged { get; set; }

        public async Task<bool> OnClosing(DialogResult result)
        {
            //if (result == DialogResult.Yes)
            //{
            //    var rows = table.SelectedRows;
            //    if (rows == null || rows.Count == 0)
            //    {
            //        await ToastService?.Error("错误", "请选择一条数据!");
            //        return false;
            //    }
            //}
            return await Task.FromResult(true);
        }

        public async Task OnClose(DialogResult result)
        {
            if (result == DialogResult.Yes)
            {
                if (ValueChanged.HasDelegate)
                {
                    await ValueChanged.InvokeAsync(designer.SaveJsonData());
                }
            }
        }
    }
}